package com.example.performance.r2dbc.entity;

import io.r2dbc.spi.Readable;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author zpMeng
 * @since 6/24/2025
 */
public class JDBCRowMapper implements RowMapper<RecordDb> {

    private static final AtomicLong count = new AtomicLong(0L);

    @Override
    public RecordDb mapRow(ResultSet rs, int rowNum) throws SQLException {
        System.out.println(count.incrementAndGet());
        return new RecordDb(
                rs.getLong("DS_ID"),
                rs.getLong("NODE_ID"),
                rs.getString("ID_COMMANDE"),
                rs.getString( "ID_CLIENT"),
                rs.getDouble( "QTE_COMMANDE"),

                rs.getLong( "DATE_EXPED_DEMAND"),
                rs.getLong( "DATE_DLUO"),
                rs.getLong( "DATE_PROD"),
                rs.getDouble( "QTE_LIVRE"),
                rs.getLong( "DATE_LIVRAISON"),
                rs.getLong( "DATE_PROD_INIT"),
                rs.getDouble( "QTE_RELIQUAT"),

                rs.getInt( "STATUT"),

                rs.getString( "text1"),
                rs.getString( "text2"),
                rs.getString( "text3"),
                rs.getString( "text4"),
                rs.getString( "text5"),
                rs.getString( "text6"),
                rs.getString( "text7"),
                rs.getString( "text8"),
                rs.getString( "text9"),
                rs.getString( "text10"),

                rs.getDouble( "qty1"),
                rs.getDouble( "qty2"),
                rs.getDouble( "qty3"),
                rs.getDouble( "qty4"),
                rs.getDouble( "qty5"),
                rs.getDouble( "qty6"),
                rs.getDouble( "qty7"),
                rs.getDouble( "qty8"),
                rs.getDouble( "qty9"),
                rs.getDouble( "qty10"),

                rs.getLong( "date1"),
                rs.getLong( "date2"),
                rs.getLong( "date3"),
                rs.getLong( "date4"),
                rs.getLong( "date5"),
                rs.getLong( "date6"),
                rs.getLong( "date7"),
                rs.getLong( "date8"),
                rs.getLong( "date9"),
                rs.getLong( "date10"),

                rs.getString( "user_modify")
        );
    }

}
